<template>
    <div>
        <table class="table">
           <tbody>
             <tr>
                <td>姓名</td>
                <td><input type="text" v-model="data.userName"></td>
            </tr>
            <tr>
                <td>密码</td>
                <td><input type="text" v-model="data.userPwd"></td>
            </tr>
            <tr>
                <td>出生日期</td>
                <td><input type="date" v-model="data.userTime"></td>
            </tr>
            <tr>
                <td>年龄</td>
                <td><input type="text" v-model="data.userAge"></td>
            </tr>
            <tr>
                <td>头像</td>
                <td>
                    <input type="file" @change="upfile">
                    <img :src="'https://localhost:7004/'+ data.userImg" style="width: 60px; height: 60px;">
                </td>
            </tr>
            <tr>
                <td>状态</td>
                <td><select v-model="data.hoteId">
                    <option value="0">请选择</option>
                    <option v-for="a in datas":value="a.hoteId">{{a.hoteName}}</option>
                </select></td>
            </tr>
            <tr>
                <td>性别</td>
                <td>
                    <input type="radio" name="xing" value="1" v-model="data.userXbie">男
                    <input type="radio" name="xing" value="2" v-model="data.userXbie">女
                </td>
            </tr>
            <tr>
                <td></td>
                <td><input type="button" value="修改" @click="postdata"></td>
            </tr>
           </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref , onMounted } from 'vue';
import { useRouter } from 'vue-router';
import { useRoute } from 'vue-router';

const route = useRoute();

const router = useRouter();

onMounted(()=>{
xiala()
fantian()
})


const datas = ref([ {
    "hoteId": 0,
    "hoteName": "string"
  }])

const xiala=()=>{
    axios.get("/api/Hote/Show").then(res=>{
    datas.value = res.data
    })
}



const data = ref({
  "userId": 0,
  "hoteId": 0,
  "userName": "string",
  "userPwd": "string",
  "userTime": "2025-06-07T02:06:16.596Z",
  "userAge": 0,
  "userImg": "string",
  "userRuzhi": true,
  "hoteName": "string",
  "userXbie": 0
})

const postdata=()=>{
    axios.put("/api/User/UpdateAsync",data.value).then(res=>{
    if(res.data>0){
    alert("修改成功")
    router.push('/')
    }
    else{
    alert("修改失败")
    }
    })
}

const upfile=(val:any)=>{

var f = val.target.files[0];
var fd = new FormData();
fd.append("file",f)

axios.post("/api/User/PostImg",fd).then(res=>{
data.value.userImg = res.data
})

}

const fantian=()=>{
    
    const mid = route.query.id;

    axios.get("/api/User/Fan",{params:{id:mid}}).then(res=>{
    data.value = res.data
    })

}

</script>

<style scoped>

</style>